<template>
  <div class="refine_tasksearch">
    <h2 class="titleblue">任务查询
      <div class="fr fr-btn" @click="daochu" v-if="false">导出</div>
    </h2>
    <div class="contant">
      <el-row :gutter="20">
        <el-col :span="12">
          <div class="grid-content bg-purple fl">
            <label>开始时间</label>
            <el-date-picker class="select-width-180" value-format='yyyy-MM-dd'
                            v-model="chooption.startTime" align="right"
                            type="date" placeholder="选择日期" :picker-options="pickerOptions1">
            </el-date-picker>
          </div>
          <div class="grid-content bg-purple fl" style="margin-left:13px">
            <label>结束时间</label>
            <el-date-picker class="select-width-180" v-model="chooption.endTime" align="right"
                            type="date" placeholder="选择日期"
                            value-format='yyyy-MM-dd' :picker-options="pickerOptions1">
            </el-date-picker>
          </div>
        </el-col>
        <el-col :span="12">
          <div class="grid-content bg-purple fl">
            <label>任务等级</label>
            <el-select clearable class="select-width-180" v-model="chooption.grade" placeholder="请选择">
              <el-option v-for="item in tasklevel" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
          </div>
          <div class="grid-content bg-purple fl" style="margin-left:13px">
            <label>任务状态</label>
            <el-select clearable class="select-width-180" v-model="chooption.taskState"
                       placeholder="请选择">
              <el-option v-for="item in taskState" :key="item.id" :label="item.name" :value="item.id">
              </el-option>
            </el-select>
          </div>
        </el-col>
        <el-col :span="12">
          <div class="grid-content bg-purple">
            <label>任务类型</label>
            <el-select clearable class="select-width-220" v-model="chooption.type1"
                       @change="typeChange($event, 'first')"
                       placeholder="请选择">
              <el-option v-for="item in taskType" :key="item.id" :label="item.name" :value="item.id">
              </el-option>
            </el-select>
            <el-select clearable class="select-width-220" v-model="chooption.type2"
                       @change="typeChange($event, 'second')"
                       placeholder="请选择" v-if="tasktype2.length">
              <el-option v-for="item in tasktype2" :key="item.id" :label="item.name" :value="item.id">
              </el-option>
            </el-select>
            <el-select clearable class="select-width-220" v-model="chooption.type3"
                       placeholder="请选择" v-if="tasktype3.length">
              <el-option v-for="item in tasktype3" :key="item.id" :label="item.name" :value="item.id">
              </el-option>
            </el-select>
          </div>
        </el-col>
        <el-col :span="12" style="text-align:left;">
          <div class="grid-content bg-purple">
            <label>任务创建</label>
            <el-select clearable class="select-width-150" v-model="create_org" placeholder="请选择"
                       @change="createChange($event)">
              <el-option v-for="(item,index) in organization" :key="index" :label="item.name" :value="item.id">
              </el-option>
            </el-select>
            <el-select clearable v-if="organizationCreate.length" class="select-width-150"
                       v-model="create_dept" @change="createChange2($event)"
                       placeholder="请选择">
              <el-option v-for="(item,index) in organizationCreate" :key="index"
                         :label="item.name ? item.name : item.fullname"
                         :value="item.id">
              </el-option>
            </el-select>
            <el-select clearable v-if="organizationCreate2.length" class="select-width-150"
                       v-model="chooption.cu_id"
                       placeholder="请选择">
              <el-option v-for="(item,index) in organizationCreate2" :key="index" :label="item.fullname"
                         :value="item.id">
              </el-option>
            </el-select>
          </div>
        </el-col>
        <el-col :span="12" style="text-align:left;">
          <div class="grid-content bg-purple">
            <label>任务派发</label>
            <el-select clearable class="select-width-200" v-model="chooption.distribute"
                       @change="sendChange($event, 'first')"
                       placeholder="请选择">
              <el-option v-for="item in organization" :key="item.id" :label="item.name" :value="item.id">
              </el-option>
            </el-select>
            <el-select clearable class="select-width-200" v-if="organization2.length"
                       @change="sendChange($event, 'second')"
                       v-model="chooption.enforcement_brigade"
                       placeholder="请选择">
              <el-option v-for="item in organization2" :key="item.id" :label="item.name" :value="item.id">
              </el-option>
            </el-select>

          </div>
        </el-col>
        <el-col :span="12" :xl='12'>
          <div class="grid-content bg-purple">
            <label>执行单元</label>
            <el-select clearable class="select-width-150" v-model="chooption.unit_people"
                       placeholder="请选择">
              <el-option v-for="item in taskperson" :key="item.id" :label="item.fullname" :value="item.id">
              </el-option>
            </el-select>
            <el-select clearable class="select-width-150" v-model="chooption.unit_carrier"
                       placeholder="请选择">
              <el-option v-for="item in taskcarrier" :key="item.id" :label="item.name" :value="item.id">
              </el-option>
            </el-select>
            <el-select clearable class="select-width-150" v-model="chooption.unit_car"
                       placeholder="请选择">
              <el-option v-for="item in taskcar" :key="item.id" :label="item.name" :value="item.id">
              </el-option>
            </el-select>
            <el-select clearable class="select-width-150" v-model="chooption.unit_tool"
                       placeholder="请选择">
              <el-option v-for="item in tasktool" :key="item.id" :label="item.name" :value="item.id">
              </el-option>
            </el-select>
          </div>
        </el-col>
        <el-col :span="12">
          <div class="grid-content bg-purple fl">
            <label style="width:69px;float:left">专项</label>
            <el-select clearable class="select-width-220" v-model="chooption.special"
                       placeholder="请选择">
              <el-option v-for="item in plans" :key="item.id" :label="item.name" :value="item.id">
              </el-option>
            </el-select>
          </div>
        </el-col>
        <el-col :span="7" style="padding:10px 0px">
          <el-col :span="12" style="padding:0">
            <div class="grid-content bg-purple" style="float:left">
              <label style="margin-right: 10px;">是否被督察</label>
              <el-checkbox v-model="chooption.inspectionOrNot" true-label=1 false-label=''>是
              </el-checkbox>
            </div>
          </el-col>
          <el-col :span="12" style="padding:0">
            <div class="grid-content bg-purple" style="float:left;">
              <label style="margin-right: 10px;">是否被评价</label>
              <el-checkbox v-model="chooption.evaluate" true-label=1 false-label=''>是</el-checkbox>
            </div>
          </el-col>
        </el-col>
        <el-col :span="12" :xl='12'>
          <div class="grid-content bg-purple">
          </div>
        </el-col>
        <el-col :span="12" :xl='12'>
          <div class="grid-content bg-purple fl">
            <el-input prefix-icon="el-icon-search" placeholder="搜索任务" clearable
                      v-model="chooption.name" class="plansearch">
            </el-input>
          </div>
          <el-button class="el-button el-button--primary" @click="search(0)">搜索</el-button>
        </el-col>
      </el-row>
      <el-tabs v-model="plantabs" type="card" @tab-click="handleClick">
        <el-table border stripe :data="tableData1" style="width: 100%" :row-class-name="tableRowClassName">
          <el-table-column prop="id" label="序号" align="center" width="60">
            <template slot-scope="scope">
              <span v-if='scope.$index!=9'>{{(currentPage-1).toString()+parseInt(scope.$index+1)}}</span>
              <span v-else>{{currentPage+'0'}}</span>
            </template>
          </el-table-column>
          <el-table-column prop="taskNo" label="任务编号" align="center">
          </el-table-column>
          <el-table-column prop="name" label="任务名称" align="center">
          </el-table-column>
          <el-table-column prop="taskUsers" label="执行单位" align="center">
            <template slot-scope="scope">
              <span v-for="item in scope.row.taskUsers">{{toUser(item.userId)}}</span>
            </template>
          </el-table-column>
          <el-table-column prop="taskTypeFlows" label="任务类型" align="center">
            <template slot-scope="scope">
              <span v-for="item in scope.row.taskTypeFlows">{{ttypes(item) ? ttypes(item) : ''}}</span>
            </template>
          </el-table-column>
          <el-table-column prop="grade" label="任务等级" align="center">
            <template slot-scope="scope">
              <span v-if="scope.row.grade == 1">一般</span>
              <span v-if="scope.row.grade == 2">紧急</span>
            </template>
          </el-table-column>
          <el-table-column prop="taskState" label="任务状态" align="center">
            <template slot-scope="scope">
              <span v-if="scope.row.taskState == 0">待指挥中心派发</span>
              <span v-else-if="scope.row.taskState == 1">待一级机构派发</span>
              <span v-else-if="scope.row.taskState == 2">待二级机构派发</span>
              <span v-else-if="scope.row.taskState == 3">已派发</span>
              <span v-else-if="scope.row.taskState == 4">已中止</span>
              <span v-else-if="scope.row.taskState == 5">已撤销</span>
              <span v-else-if="scope.row.taskState == 6">已超期</span>
              <span v-else-if="scope.row.taskState == 7">暂存</span>
              <span v-else-if="scope.row.taskState == 8">已完成</span>
              <span v-else-if="scope.row.taskState == 9">已派发</span>
              <span v-else-if="scope.row.taskState == 10">正执行</span>
            </template>
          </el-table-column>
          <el-table-column prop="deadline" label="完成时间" align="center">
            <template slot-scope="scope">
              <span>{{scope.row.finishTime ? $m(scope.row.finishTime).format('YYYY-MM-DD') : ''}}</span>
            </template>
          </el-table-column>
          <el-table-column prop="operate" label="操作" align="center" width="140">
            <template slot-scope="scope">
              <el-button size="mini" type="text" v-if="scope.row.createUserName==username && scope.row.taskState != 5 && scope.row.taskState != 4"
                         @click="manipulate({data: scope.row, action: 'revoke'})">撤销
              </el-button>
              <el-button size="mini" type="text" v-if="scope.row.createUserName==username && scope.row.taskState != 4 && scope.row.taskState != 5"
                         @click="manipulate({data: scope.row, action: 'stop'})">中止
              </el-button>
              <el-button size="mini" type="text" @click="manipulate({data: scope.row, action: 'view'})">查看</el-button>
            </template>
          </el-table-column>
        </el-table>
        <div class="block">
          <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                         :current-page.sync="currentPage" layout="total,prev, pager, next, jumper"
                         :total="total" background>
          </el-pagination>
        </div>
      </el-tabs>

      <!--<data-table :page='currentPage' :head="thead1" :data="tableData1" :operate="toptions"-->
      <!--:actions="['edit','revoke','view']" @callback="manipulate" class="intendance-table"></data-table>-->
      <!-- <ttable :page='currentPage' :thead="thead1" :tdata="tableData1" :operate="toptions" @te="manipulate" class="intendance-table" @tlook="tablelook"></ttable> -->

      <!--   任务查询  -->
      <router-view @close='close'></router-view>
    </div>
  </div>
</template>

<script>
  import DataTable from '@/components/common/DataTable.vue'
  import TaskDetail from './TaskDetail.vue'
  import moment from 'moment'
  import taskService from '@/services/TaskService.js'
  import taskTypeService from '@/services/TaskTypeService'
  import plansService from '@/services/PlansService'
  import taskObjectService from '@/services/TaskObjectService'
  import * as organizationService from '@/services/OrganizationService'
  import * as sysUserService from '@/services/SysUserService'

  export default {
    components: {
      'data-table': DataTable,
      'task-detail': TaskDetail
    },
    data: function () {
      return {
        taskDetail: [],
          username: '',
        chooption: {
          startTime: '',
          endTime: '',
          grade: '',
          enforcement_brigade: '',
          distribute: '',
          taskState: '',
          type1: '',
          type2: '',
          type3: '',
          unit_people: '',
          unit_carrier: '',
          unit_car: '',
          unit_tool: '',
          inspectionOrNot: '',
          name: '',
          evaluate: '',
          special: '',
          cu_org: '',
          cu_id: '',
        },
        member: '',
        successDialog: false,
        type_first: [],
        type_second: [],
        taskO: [],
        create_first: [],
        create_second: [],
        create_third: [],

        create_org: '',
        create_dept: '',
        tasklevel: [{
          label: '一般',
          value: 1
        }, {
          label: '紧急',
          value: 2
        }],
        taskstatus: [],
        taskperson: [],
        taskcarrier: [],
        taskcar: [],
        tasktool: [],
        // tasktype: [],
        tasktype1: [],
        tasktype2: [],
        specialArr: [],
        idStr: [],
        ids: [],
        pickerOptions1: {
          // disabledDate(time) {
          //   return time.getTime() > Date.now();
          // },
          shortcuts: [{
            text: '今天',
            onClick(picker) {
              picker.$emit('pick', new Date())
            }
          }, {
            text: '昨天',
            onClick(picker) {
              const date = new Date()
              date.setTime(date.getTime() - 3600 * 1000 * 24)
              picker.$emit('pick', date)
            }
          }, {
            text: '一周前',
            onClick(picker) {
              const date = new Date()
              date.setTime(date.getTime() - 3600 * 1000 * 24 * 7)
              picker.$emit('pick', date)
            }
          }]
        },
        thead1: [
          {name: '任务编号', prop: 'tasknumber'},
          {name: '任务名称', prop: 'name'},
          {name: '所属辖区', prop: 'distribute_name'},
          {name: '任务类型', prop: 'type_name'},
          {name: '任务等级', prop: 'grade_name'},
          {name: '任务状态', prop: 'star_name'},
          {name: '完成时间', prop: 'endTime'},
        ],
        tableData1: [],
        tableData2: [],
        toptions: [{name: '撤销', prop: 'cancel'}, {name: '中止', prop: 'stop'}, {name: '查看', prop: 'look'}],
        taskState: [
          {name: '待派发', id: 3},
          {name: '已完成', id: 8},
          {name: '执行中', id: 10},
          {name: '已中止', id: 4},
          {name: '已撤销', id: 5},
          {name: '已超期', id: 6},
          {name: '待领取', id: 9},
        ],
        currentPage: 1,
        total: 0,
        currentPage2: 1,
        total2: 0,
        taskType: [],
        organization: [],
        sysUser: [],
        plans: [],
        tasktype3: [],
        organization2: [],
        organizationCreate: [],
        organizationCreate2: [],
        taskObjectType: [],
        plantabs: 'first'
      }
    },
    created() {
      let level = this.$profile.organiza.level
      if (level == 0) {
        this.thead1 = [
          {name: '任务编号', prop: 'taskNo'},
          {name: '任务名称', prop: 'name'},
          {name: '执行单位', prop: 'organiza'},
          {name: '任务类型', prop: 'taskTypeFlows '},
          {name: '任务等级', prop: 'grade'},
          {name: '任务状态', prop: 'taskState'},
          {name: '完成时间', prop: 'endTime'},

        ]
      } else {
        this.thead1 = [
          {name: '任务编号', prop: 'taskNo'},
          {name: '任务名称', prop: 'name'},
          {name: '派发单位', prop: 'organiza'},
          {name: '执行单位', prop: 'enforcementbrigade_name'},
          {name: '任务类型', prop: 'taskTypeFlows '},
          {name: '任务等级', prop: 'grade'},
          {name: '任务状态', prop: 'taskState'},
          {name: '完成时间', prop: 'endTime'},
        ]
      }
        this.username = this.$profile.fullname
      this.getSelect()
      this.search(0, this.plantabs)
    },
    methods: {
      //  标签页切换函数
      handleClick(tab, event) {
          this.currentPage = 1
          this.currentPage2 = 1
          this.search(0, this.plantabs)
      },
      tableRowClassName({ row, rowIndex }) {

        if (row.taskState == '2' || row.taskState == '0' || row.taskState == '1') {
          return 'warning-row';
        } else if (row.taskState == '8') {
          return 'success-row';
        } else if (row.taskState == '10') {
          return 'done-row';
        } else if (row.taskState == '4' || row.taskState == '5' || row.taskState == '6') {
          return 'over-row';
        }
        return '';

      },
      toUser(id) {
        let obj
        if (id) {
          obj = this.sysUser.find(item => {
            return item.id == id
          })
        }
        if (obj) {
          return obj.fullname
        }
      },
      ttypes(item) {
        let task = ''
        let obj1 = {}, obj2 = {}, obj3 = {}
        if (item.type1) {
          for (let task of this.taskType) {
            if (task.id == item.type1) obj1 = task
          }
          task = obj1 ? obj1.name : ''
          if (obj1 && obj1.subset) {
            for (let task of obj1.subset) {
              if (task.id == item.type2) obj2 = task
            }
            if (item.type2) task = obj2 ? obj2.name : ''
            if (obj2 && obj2.subset && item.type2) {
              for (let task of obj2.subset) {
                if (task.id == item.type3) obj3 = task
              }
              if (obj3 && item.type3) {
                task = obj3.name
              }
            }
          }
        }
        return task
      },
      search(num = 0, type) {
        if (num == 0) {
          this.$set(this, 'currentPage', 1)
          this.$set(this, 'currentPage2', 1)
        }
        let str = this.handlerQuery()

        taskService.criteriaQueries(num, str, 10).then(res => {
            // if (type == 'first') {
                this.tableData1 = res.data
                this.total = parseInt(res.headers['x-total-count'], 10)
            // } else if (type == 'second') {
            //     this.tableData2 = res.data
            //     this.total2 = parseInt(res.headers['x-total-count'], 10)
            // }
        })
        // let str = this.handlerQuery()
        // taskService.ps(num).then(res => {
        //   this.tableData1 = res.data
        //   this.total = res.dataCount
        // })
      },
      // 处理拼接query
      handlerQuery() {
        let str = ''
        if (this.chooption.startTime) {
          str += 'begineTime.greaterOrEqualThan=' + moment(this.chooption.startTime).toISOString()
        }
        if (this.chooption.endTime) {
          if (str) {
            str += '&'
          }
          str += 'endTime.lessOrEqualThan=' + moment(this.chooption.endTime).toISOString()
        }
        if (this.chooption.grade) {
          if (str) {
            str += '&'
          }
          str += 'grade.equals=' + this.chooption.grade
        }
        if (this.chooption.taskState) {
          if (str) {
            str += '&'
          }
          str += 'taskState.equals=' + this.chooption.taskState
        }
          if (this.chooption.type1) {
              if (str) {
                  str += '&'
              }
              str += 'taskTypeFlowId1.equals=' + this.chooption.type1
          }
          if (this.chooption.type2) {
              if (str) {
                  str += '&'
              }
              str += 'taskTypeFlowId2.equals=' + this.chooption.type2
          }
          if (this.chooption.type3) {
              if (str) {
                  str += '&'
              }
              str += 'taskTypeFlowId3.equals=' + this.chooption.type3
          }
          // if (this.plantabs == 'second') {
          //     if (str) {
          //         str += '&'
          //     }
          //     str += 'unionFlag.equals=' + true
          // } else if (this.plantabs == 'first') {
          //     if (str) {
          //         str += '&'
          //     }
          //     str += 'unionFlag.equals=' + false
          // }
        // if (this.chooption.distribute) {
        //   if (str) {
        //     str += '&'
        //   }
        //   str += 'organizaId.equals=' + (this.chooption.enforcement_brigade ? this.chooption.enforcement_brigade : this.chooption.distribute)
        // }
        if (this.chooption.enforcement_brigade) {
            if (str) {
                str += '&'
            }
            let orgObj2 = this.organization2.find(async item => {
                return item.id == this.chooption.enforcement_brigade
            })
            if (orgObj2.businessOrg == 5) { // 指挥中心
                str += 'centerTaskFlag.equals=true'
            } else if (orgObj2.businessOrg == 1 || orgObj2.businessOrg == 2) { // 业务部门 || 行政部门
                str += 'businessUnit.equals=' + this.chooption.enforcement_brigade
            } else if (orgObj2.businessOrg == 3) { // 海事处
                str += 'managementUnit.equals=' + this.chooption.enforcement_brigade
            } else if (orgObj2.businessOrg == 4) { // 执法大队
                str += 'enforcementBrigade.equals=' + this.chooption.enforcement_brigade
            } else if (orgObj2.businessOrg == 0) { // 局领导
                // str = str.substring(0, str.length - 1)
                str += 'enforcementBrigade.equals=' + -1
            }
            // str += 'enforcementBrigade.equals=' + this.chooption.distribute
        } else if (this.chooption.distribute) {
            if (str) {
                str += '&'
            }
            let orgObj = this.organization.find(item => {
                return item.id == this.chooption.distribute
            })
            if (orgObj.businessOrg == 5) { // 指挥中心
                str += 'centerTaskFlag.equals=true'
            } else if (orgObj.businessOrg == 1 || orgObj.businessOrg == 2) { // 业务部门 || 行政部门
                str += 'businessUnit.equals=' + this.chooption.distribute
            } else if (orgObj.businessOrg == 3) { // 海事处
                str += 'managementUnit.equals=' + this.chooption.distribute
            } else if (orgObj.businessOrg == 4) { // 执法大队
                str += 'enforcementBrigade.equals=' + this.chooption.distribute
            } else if (orgObj.businessOrg == 0) { // 局领导
                // str = str.substring(0, str.length - 1)
                str += 'enforcementBrigade.equals=' + -1
            }
            // str += 'managementUnit.equals=' + this.chooption.distribute
        }
        if (this.create_org) {
          if (str) {
            str += '&'
          }
          str += 'createUserId.equals=' + (this.chooption.cu_id ? this.chooption.cu_id : (this.create_dept ? this.create_dept : this.create_org))
        }
        if (this.chooption.special) {
          if (str) {
            str += '&'
          }
          str += 'special.contains=' + this.chooption.special
        }
        if (this.chooption.inspectionOrNot) {
          if (str) {
            str += '&'
          }
          str += 'superviseFlag.equals=' + this.chooption.inspectionOrNot
        }
        if (this.chooption.evaluate) {
          if (str) {
            str += '&'
          }
          str += 'needExamine.equals=' + this.chooption.evaluate
        }
        if (this.chooption.name) {
          if (str) {
            str += '&'
          }
          if (isNaN(this.chooption.name.trim())){
              str += 'name.contains=' + this.chooption.name
          } else {
              str += 'taskNo.contains=' + this.chooption.name
          }
        }
        if (this.create_org) {
          if (str) {
            str += '&'
          }
          str += 'createUserId.equals=' + this.chooption.cu_id ? this.chooption.cu_id : (this.create_dept ? this.create_dept : this.create_org)
        }
        return str
      },
      async createChange(val) {
        this.organizationCreate = []
        this.organizationCreate2 = []
        this.create_dept = ''
        this.chooption.cu_id = ''
        let type = await this.organization.find(item => {
          return item.id == val
        })
        if (type && type.sub) {
          this.$set(this, 'organizationCreate', type.sub)
        } else {
          let arr = await this.sysUser.filter(fil => {
            if (fil.organiza) {
              return fil.organiza.id == val
            }
          })
          arr.sort((a, b) => {
              if (a.level < b.level) {
                  return 1
              } else {
                  return -1
              }
              return 0
          })
          this.$set(this, 'organizationCreate', arr)
        }
      },
      async createChange2(val) {
        this.organizationCreate2 = []
        this.chooption.cu_id = ''
        let arr = await this.sysUser.filter(fil => {
          if (fil.organiza) {
            return fil.organiza.id == val
          }
        })
        if (arr) {
          arr.sort((a, b) => {
              if (a.level < b.level) {
                  return 1
              } else {
                  return -1
              }
              return 0
          })
          this.$set(this, 'organizationCreate2', arr)
        }
      },
      async sendChange(val, kind) {
        if (kind == 'first') {
          this.organization2 = []
          this.chooption.enforcement_brigade = ''
          let type = this.organization.find(item => {
            return item.id == val
          })
          if (type && type.sub) {
            this.$set(this, 'organization2', type.sub)
          }
        }
        this.taskperson = []
        this.chooption.unit_people = ''
        let arr = await this.sysUser.filter(fil => {
          if (fil.organiza) {
            return fil.organiza.id == val
          }
        })
        if (arr) {
          arr.sort((a, b) => {
            if (a.level < b.level) {
              return 1
            } else {
              return -1
            }
            return 0
          })
          this.$set(this, 'taskperson', arr)
        }
      },
      typeChange(val, kind) {
        if (kind == 'first') {
          this.chooption.type2 = ''
          this.chooption.type3 = ''
          this.tasktype2 = []
          this.tasktype3 = []
          let type = this.taskType.find(item => {
            return item.id == val
          })
          if (type && type.subset) {
            this.tasktype2 = type.subset
          }
        } else if (kind == 'second') {
          this.chooption.type3 = ''
          this.tasktype3 = []
          let type = this.tasktype2.find(item => {
            return item.id == val
          })
          if (type && type.subset) {
            this.tasktype3 = type.subset
          }
        }
      },
      getSelect() {
        taskTypeService.search().then(res => {

          this.taskType = res
        })
        organizationService.findAll().then(async res => {
          await res.data.sort((a, b) => {
            if (a.businessOrg < b.businessOrg) {
              return -1
            }
            if (a.businessOrg > b.businessOrg) {
              return 1
            }
            return 0
          })
          this.organization = res.data
          // this.organizaAll = res.dataAll
        })
        sysUserService.findAll().then(res => {
          this.sysUser = res.data
        })
        plansService.searchAll().then(res => {
          this.plans = res
        })
        taskObjectService.search().then(res => {
          this.taskObjectType = res
        })
      },
      // search () {
      //
      // },
      changeType() {
        // this.tasktype2 = []
        // this.chooption.tasktype2 = ''
        // for (var i of this.tasktype) {
        //   if (i.d_id == this.chooption.type_first) {
        //     for (var j of i.son) {
        //       this.tasktype2.push({
        //         label: j.name,
        //         value: j.d_id
        //       })
        //     }
        //   }
        // }
        // this.search('1', this.currentPage)
      },
      changeOrg(val) {
        // this.taskperson = []
        // this.taskcarrier = []
        // this.taskcar = []
        // this.tasktool = []
        // this.type_second = []
        // this.chooption.unit_people = ''
        // this.chooption.unit_carrier = ''
        // this.chooption.unit_car = ''
        // this.chooption.unit_tool = ''
        // this.chooption.enforcement_brigade = ''
        // for (var i of this.taskO) {
        //   if (i.d_id == this.chooption.distribute) {
        //     for (var j of i.son) {
        //       this.type_second.push({
        //         label: j.name,
        //         value: j.d_id
        //       })
        //     }
        //
        //   }
        // }
        // if (val) {
        //   this.$axios.get(this.$config['disUser'], {
        //     params: {
        //       skey: localStorage.getItem('auth'),
        //       dId: val
        //     }
        //   }).then((res) => {
        //     this.taskperson = res.data.content
        //   })
        //   this.$axios.get(this.$config['searchLawUnit'], {
        //     params: {
        //       skey: localStorage.getItem('auth'),
        //       orgId: val
        //     }
        //   }).then((res) => {
        //     ;
        //     var data = res.data.content
        //     this.taskcar = data.cars
        //     this.taskcarrier = data.ships
        //     this.tasktool = data.tools
        //   })
        //
        // }
        // this.search('1', this.currentPage)
      },
      changeDept(val) {
        // this.taskperson = []
        // this.taskcarrier = []
        // this.taskcar = []
        // this.tasktool = []
        // this.chooption.unit_people = ''
        // this.chooption.unit_carrier = ''
        // this.chooption.unit_car = ''
        // this.chooption.unit_tool = ''
        // if (val) {
        //   this.$axios.get(this.$config['disUser'], {
        //     params: {
        //       skey: localStorage.getItem('auth'),
        //       dId: val
        //     }
        //   }).then((res) => {
        //     this.taskperson = res.data.content
        //   })
        //   this.$axios.get(this.$config['searchLawUnit'], {
        //     params: {
        //       skey: localStorage.getItem('auth'),
        //       orgId: val
        //     }
        //   }).then((res) => {
        //     ;
        //     var data = res.data.content
        //     this.taskcar = data.cars
        //     this.taskcarrier = data.ships
        //     this.tasktool = data.tools
        //   })
        //
        // }
        // this.search('1', 1)
      },
      manipulate(param) {
        if (param.action == 'revoke') {
          this.$confirm('此操作将撤销该任务, 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          })
            .then(() => {
              taskService.update({id: param.data.id}, 4).then(res => {
                if (res) {
                  this.search(0, this.plantabs)
                  this.$message({
                    type: 'success',
                    message: '撤销成功'
                  })
                }
              })
            })
            .catch(() => {

            })
        } else if (param.action == 'stop') {
          this.$confirm('此操作将中止该任务, 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          })
            .then(() => {
              taskService.update({id: param.data.id}, 7).then(res => {
                if (res) {
                  this.search(0, this.plantabs)
                  this.$message({
                    type: 'success',
                    message: '任务已中止'
                  })
                }
              })
            })
            .catch(() => {

            })
        } else if (param.action == 'view') {
          // this.taskDetail = param.data
          this.successDialog = true
          this.$router.push({name: 'searchDetail', params: {data: param.data, pageType: 'search'}})
        }
      },
      handleSizeChange(val) {
        this.search(val - 1, this.plantabs)
      },
      handleCurrentChange(val) {
        this.search(val - 1, this.plantabs)
      },
      handleSizeChange2(val) {
          this.search(val - 1, this.plantabs)
      },
      handleCurrentChange2(val) {
          this.search(val - 1, this.plantabs)
      },
      close() {
        this.successDialog = false
        this.search(0, this.plantabs)
        this.$router.push("/task-search")
        // this.search('1', this.currentPage)
      },
      daochu() {
        this.ids = []
        for (var i of this.tableData1) {
          this.ids.push(i.d_id)
        }
        this.$axios.get('TaskExportTask', {
          params: {
            skey: localStorage.getItem('auth'),
            idStr: this.ids.join(',')
          }
        }).then((res) => {
          window.open(this.$config['imgUrl'] + res.data.content)
        })
      },
      createOrg(val) {
        // this.create_dept = ''
        // this.chooption.cu_id = ''
        // this.create_third = []
        // this.create_second = []
        // for (var i of this.taskO) {
        //   if (i.d_id == this.create_org) {
        //     for (var x of i.son) {
        //       this.create_second.push({
        //         label: x.name,
        //         value: x.d_id
        //       })
        //     }
        //
        //   }
        // }
        // if (val) {
        //   this.$axios.get(this.$config['disUser'], {
        //     params: {
        //       skey: localStorage.getItem('auth'),
        //       dId: val
        //     }
        //   }).then((res) => {
        //     this.create_third = res.data.content
        //   })
        // }
        // this.chooption.cu_org = this.create_org
        // this.search('1', 1)
      },
      createDept(val) {
        // this.chooption.cu_id = ''
        // this.create_third = []
        // if (val) {
        //   this.$axios.get(this.$config['disUser'], {
        //     params: {
        //       skey: localStorage.getItem('auth'),
        //       dId: val
        //     }
        //   }).then((res) => {
        //     this.create_third = res.data.content
        //   })
        // }
        // this.chooption.cu_org = this.create_dept
        // this.search('1', 1)

      },
      createPerson() {
        // this.search('1', 1)
      }
    }
  }
</script>
<style>
  .el-table .warning-row {
    background: #fe6e6e;
  }

  .el-table .success-row {
    background: #e0e0e0;
  }

  .el-table .done-row {
    background: #47ec6a;
  }

  .el-table .over-row {
    background: #b3b3b3;
  }
</style>
<style lang="scss" scoped>

  .refine_tasksearch {
    .fr-btn {
      margin-right: 80px;
      cursor: pointer;
    }

    .contant {
      padding-bottom: 20px;

      .select-width-100 {
        width: 125px;
      }

      .select-width-150 {
        width: 154px;
      }

      .select-width-200 {
        width: 200px;
      }

      .select-width-180 {
        width: 166px;

      }

      .el-table .warning-row:hover > td {
        background: #fe6e6e !important
      }

      .el-table .success-row:hover > td {
        background: #e0e0e0 !important
      }

      .el-table .done-row:hover > td {
        background: #47ec6a !important
      }

      .el-table .over-row:hover > td {
        background: #b3b3b3 !important
      }

      .el-table .warning-row:hover {
        background: #fe6e6e !important
      }

      .el-table .success-row:hover {
        background: #e0e0e0 !important
      }

      .el-table .done-row:hover {
        background: #47ec6a !important
      }

      .el-table .over-row:hover {
        background: #b3b3b3 !important
      }

      .el-table tr:hover {
        background: transparent
      }

      .el-table--enable-row-hover .el-table__body tr:hover > td {
        background: transparent
      }

      .el-col {
        padding: 10px 0px;
        padding-left: 0px !important;
        padding-right: 0px !important;

        .grid-content label {
          line-height: 40px;
        }

        .select-width-220 {
          width: 234px;
        }

        .plansearch {
          float: left;
          margin-left: 5px;
          width: 236px;
        }

        .plansearch input {
          width: 230px;
          margin-right: 10px;
          border-radius: 0;
        }

        .plansearch .el-input-group__append {
          border-left: 1px;
          width: 56px;
          background-color: #0062cd;
          border-radius: 2px;
          font-size: 14px;
          color: #ffffff;
        }
      }

      .intendance-table {
        margin-top: 20px;
      }

      .el-pagination {
        margin-top: 40px;
        text-align: center;
      }
    }
  }

  @media screen and (min-width: 1200px) and (max-width: 1365px) {
    .refine_tasksearch {
      .select-width-100 {
        width: 125px !important;
      }

      .select-width-150 {
        width: 134px !important;
      }

      .select-width-200 {
        width: 180px !important;
      }

      .select-width-180 {
        width: 146px !important;
      }

      .select-width-220 {
        width: 214px !important;
      }
    }
  }

  @media screen and (max-width: 1919px) {
    .refine_tasksearch {
      .select-width-100 {
        width: 125px !important;
      }

      .select-width-150 {
        width: 120px !important;
      }

      .select-width-200 {
        width: 170px !important;
      }

      .select-width-180 {
        width: 140px !important;
      }

      .select-width-220 {
        width: 170px !important;
      }

    }
  }
</style>
